package com.haochang.chunkvod.controller.adapter.cash;

import java.util.List;

import com.haochang.base.BaseListView;
import com.haochang.base.OnBaseClickListener;
import com.haochang.chunkvod.R;
import com.haochang.chunkvod.app.utils.ScreenUtils;
import com.haochang.chunkvod.controller.adapter.base.BaseAdapterHelper;
import com.haochang.chunkvod.controller.adapter.base.QuickAdapter;
import com.haochang.chunkvod.model.cash.CouponInfo;
import com.haochang.chunkvod.view.vod.ViewGroup.CouponView;
import com.haochang.chunkvod.view.vod.dialog.VodCustomDialog;

import android.content.Context;
import android.view.View;

/**
 * 卷详情适配器
 */
public class CouponsDetailsAdapter extends QuickAdapter<CouponInfo>
{
	private Context context;
	private int keyOfTag = R.id.coupon_item_id;

	public CouponsDetailsAdapter(Context context, int layoutResId, List<CouponInfo> list)
	{
		super(context, layoutResId, list);
		this.context = context;
	}

	@Override
	protected void convert(BaseAdapterHelper helper, final CouponInfo item)
	{
		((CouponView) helper.getView(R.id.couponView)).setBackgroundColor_(context.getResources().getColor(0 == item.getType() ? R.color.red : R.color.orange));
		helper.setText(R.id.tv_title, String.valueOf(item.getName()));
		helper.setText(R.id.tv_content, 0 == item.getType() ? "代金券" : "优惠券");
		helper.setText(R.id.tv_count, String.valueOf(item.getCount() + item.getUnit()));
		helper.getView().setTag(keyOfTag, item);
		helper.getView().setOnClickListener(onBaseClickListener);
	}

	OnBaseClickListener onBaseClickListener = new OnBaseClickListener()
	{
		@Override
		public void onBaseClick(View v)
		{
			final CouponInfo info = (CouponInfo) v.getTag(keyOfTag);
			if (null != info)
			{
				CouponInfo info1 = new CouponInfo();
				info.getArrayList().add(info1);
				info.getArrayList().add(info1);
				new VodCustomDialog.Builder(context).setTitle("券详情").showDialog(R.layout.inflate_vod_custom_dialog_listview,
						ScreenUtils.getScreenHight(context) / 2, new VodCustomDialog.OnViewAddedListener()
						{
							@Override
							public void getView(View view)
							{
								((BaseListView) view.findViewById(R.id.listView))
										.setAdapter(new QuickAdapter<CouponInfo>(context, R.layout.item_ticket_detail, info.getArrayList())
										{
											@Override
											protected void convert(BaseAdapterHelper helper, CouponInfo item)
											{
												helper.setText(R.id.tv_content,
														"我是内容1\n" + "我是内容2\n" + "我是内容3\n" + "我是内容4\n" + "我是内容4\n" + "我是内容4\n" + "我是内容4\n我是内容1\n" + "我是内容2\n"
																+ "我是内容3\n" + "我是内容4\n" + "我是内容4\n" + "我是内容4\n" + "我是内容4\n" + "我是内容4\n我是内容1\n" + "我是内容2\n"
																+ "我是内容3\n" + "我是内容4\n" + "我是内容4\n" + "我是内容4\n" + "我是内容4");
												helper.setText(R.id.tv_ticket_code, "我是券码01010104144");
												//helper.setText(R.id.tv_content, item.getContent());
												//helper.setText(R.id.tv_ticket_code, item.getName());
											}
										});
							}
						});
			}
		}
	};
}
